/**
* @file panic.cpp
* Code for handle unxpected and critical states of kernel.
*
* Copyrights 2010 Michal Saman, m.saman@designplus.cz
* This source code is release under the Apache License 2.0.
* http://www.apache.org/licenses/LICENSE-2.0
*/

#include <stdarg.h>
#include <stdint.h>
#include <hal/hal.h>
#include <main/kprintf.h>
#include <main/textconst.h>

/**
* Routine to handle unexcepted kernal state.
* @param *fmt String descripting state of kernel, can be formatted.
* @param ... Parameters for formatted string.
*/
void __attribute__ ((cdecl)) kernel_panic(const char *fmt, ...) {
	disable_interrupts();

	va_list  args;
	static uint8_t buf[1024];

	va_start(args, fmt);

	// we will need a vsprintf() here... TODO

	va_end(args);

	vga_text_mode_clr_scr(0x1F);
	vga_text_mode_gotoXY(0,0);
	vga_text_mode_set_color(0x1F);

	kprintf(kernel_panic_disclaimer);
	kprintf("~~ CRITICAL STOP: %s", fmt);

	for (;;);
}
